import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.SQLException;

public class Main {
    public static void main(String[] args) throws SQLException {

/*        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/study?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("1234");

        Connection connection = (Connection) dataSource.getConnection();
        //String sql = "insert into students values('刘六',1)";
        String sql = "delete from students where name = '刘六' ";

        PreparedStatement statement = connection.prepareStatement(sql);
        int n = statement.executeUpdate();
        System.out.println(n);

        statement.close();
        connection.close();*/

        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/study?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("1234");

        Connection connection = (Connection) dataSource.getConnection();
        String sql = "insert into students values('刘六',1)";

        PreparedStatement statement = (PreparedStatement) connection.prepareStatement(sql);
        int n = statement.executeUpdate();
        System.out.println(n);
        statement.close();
        connection.close();

    }
}
